#include "bsp_keyfilter.h"
#include "bsp_gpio.h"
#include "bsp_epit.h"
#include "bsp_exit.h"
#include "bsp_beep.h"
static void (*key_cb)(int);
void keyfilter_init()
{
    exit_init();
    // epit 配置
    epit_init(EPIT1, 0, 66 * 10^6 / 100);
}
static void key_irq_handle(uint32_t nirq, void* arg)
{
    epit_restart(EPIT1, 66000000/100);
    gpio_clr_ints(GPIO1, BSP_GPIO_PIN_18);
}
static void epit_irq_handle(uint32_t nirq, void* arg)
{
    if (EPIT1->SR && 1)
    {
        epit_stop(EPIT1);
        if (gpio_pinread(GPIO1, 18) == 0)
        {
            key_cb(1);
        }
    }
    epit_clr_isr(EPIT1);
}
void keyfilter_enable(void (*on_key)(int))
{
    exit_set_irq_handler(key_irq_handle, NULL);
    epit_enable(EPIT1, EPIT1_IRQn, epit_irq_handle, NULL);
    epit_stop(EPIT1);
    key_cb = on_key;
}
